package com.ebelter.bodyfatscale.util;


import android.os.SystemClock;

import com.ebelter.btlibrary.util.ULog;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;

public class MyExceptionHandler implements Thread.UncaughtExceptionHandler{
    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        ULog.e("MyExceptionHandler","currentThread:"+Thread.currentThread()+"---thread:"+thread.getId()+"---ex:"+ex.toString());//01


        Writer info = new StringWriter();
        PrintWriter printWriter = new PrintWriter(info);
        ex.printStackTrace(printWriter);
        Throwable cause = ex.getCause();
        while (cause != null) {
            cause.printStackTrace(printWriter);
            cause = cause.getCause();
        }
        String result = info.toString();
        printWriter.close();

        ULog.i("MyExceptionHandler","printStackTrace:"+result);//02
        ULog.i("MyExceptionHandler","getLocalizedMessage():"+ex.getLocalizedMessage());
        ULog.i("MyExceptionHandler","getMessage():"+ex.getMessage());
        SystemClock.sleep(3000);
        android.os.Process.killProcess(android.os.Process.myPid());
    }
}
